home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume13 / rpc3.9 / part14 < prev    next >
Encoding:
Internet Message Format  |  1988-02-27  |  35.1 KB

  1. Subject:  v13i091:  Sun RPC, release 3.9, Part14/15
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Stephen X. Nahm <sxn@Sun.COM>
  7. Posting-number: Volume 13, Issue 91
  8. Archive-name: rpc3.9/part14
  9.  
  10. #! /bin/sh
  11. # This is a shell archive. To extract, remove the header and type "sh filename"
  12. #
  13. cd doc
  14. echo x - Makefile
  15. cat > Makefile <<'Funky_Stuff'
  16. #
  17. # @(#)Makefile    1.4 87/11/18 3.9 RPCSRC
  18. #
  19. #
  20. #   The targets all.nroff and all.troff will make monolithic documents
  21. #   with nroff and troff, respectively.  The other *.nroff and *.troff
  22. #   targets will make individual documents
  23. #
  24. TROFF=    ditroff
  25. TOPTS=  -t
  26. NROFF=    nroff
  27. NOPTS=
  28. PIC=    pic
  29. TBL=    tbl
  30. EQN=    eqn
  31.  
  32. SRC=     rpc.prog.ms rpcgen.ms xdr.nts.ms xdr.rfc.ms rpc.rfc.ms nfs.rfc.ms
  33.  
  34. all default: all.nroff
  35.  
  36. install:    all.nroff
  37.     @echo "Nothing installed."
  38.  
  39. all.nroff:    ${SRC}
  40.     ${TBL} ${SRC} | ${EQN} | ${NROFF} ${NOPTS} -ms >all.nroff
  41.  
  42. all.troff:    ${SRC}
  43.     ${TBL} ${SRC} | ${PIC} | ${EQN} | ${TROFF} ${TOPTS} -ms >all.troff
  44.  
  45. #
  46.  
  47. rpc.prog.nroff: rpc.prog.ms
  48.     ${TBL} rpc.prog.ms | ${NROFF} ${NOPTS} -ms >rpc.prog.nroff
  49.  
  50. rpc.prog.troff:    rpc.prog.ms
  51.     ${TBL} rpc.prog.ms | ${PIC} | ${TROFF} ${TOPTS} -ms >rpc.prog.troff
  52.  
  53. #
  54.  
  55. rpcgen.troff:    rpcgen.ms
  56.     ${TBL} rpcgen.ms | ${TROFF} ${TOPTS} -ms >rpcgen.troff
  57.  
  58. rpcgen.nroff:    rpcgen.ms
  59.     ${TBL} rpcgen.ms | ${NROFF} ${NOPTS} -ms >rpcgen.nroff
  60.  
  61. #
  62.  
  63. xdr.nts.troff: xdr.nts.ms
  64.     ${TBL} xdr.nts.ms | ${EQN} | ${TROFF} ${TOPTS} -ms >xdr.nts.troff
  65.  
  66. xdr.nts.nroff: xdr.nts.ms
  67.     ${TBL} xdr.nts.ms | ${EQN} | ${NROFF} ${NOPTS} -ms >xdr.nts.nroff
  68.  
  69. #
  70.  
  71. xdr.rfc.troff: xdr.rfc.ms
  72.     ${TBL} xdr.rfc.ms | ${TROFF} ${TOPTS} -ms >xdr.rfc.troff
  73.  
  74. xdr.rfc.nroff: xdr.rfc.ms
  75.     ${TBL} xdr.rfc.ms | ${NROFF} ${NOPTS} -ms >xdr.rfc.nroff
  76.  
  77. #
  78.  
  79. rpc.rfc.troff: rpc.rfc.ms
  80.     ${TBL} rpc.rfc.ms | ${TROFF} ${TOPTS} -ms >rpc.rfc.troff
  81.  
  82. rpc.rfc.nroff: rpc.rfc.ms
  83.     ${TBL} rpc.rfc.ms | ${NROFF} ${NOPTS} -ms >rpc.rfc.nroff
  84.  
  85. #
  86.  
  87. nfs.rfc.troff: nfs.rfc.ms
  88.     ${TBL} nfs.rfc.ms | ${TROFF} ${TOPTS} -ms >nfs.rfc.troff
  89.  
  90. nfs.rfc.nroff: nfs.rfc.ms
  91.     ${TBL} nfs.rfc.ms | ${NROFF} ${NOPTS} -ms >nfs.rfc.nroff
  92.  
  93. clean:
  94.     rm -f *.nroff *.troff
  95.  
  96. spell:    ${SRC}
  97.     @for i in ${SRC}; do \
  98.         echo $$i; spell $$i | sort | comm -23 - spell.ok > $$i.spell; \
  99.     done
  100. Funky_Stuff
  101. len=`wc -c < Makefile`
  102. if [ $len !=     1822 ] ; then
  103.   echo error: Makefile was $len bytes long, should have been     1822
  104. fi
  105. echo x - xdr.rfc.ms
  106. sed -e 's/^X//' > xdr.rfc.ms <<'Funky_Stuff'
  107. X.\" @(#)xdr.rfc.ms    1.2 87/11/09 3.9 RPCSRC
  108. X.de BT
  109. X.if \\n%=1 .tl ''- % -''
  110. X..
  111. X.ND
  112. X.\" prevent excess underlining in nroff
  113. X.if n .fp 2 R
  114. X.OH 'eXternal Data Representation Standard''Page %'
  115. X.EH 'Page %''eXternal Data Representation Standard'
  116. X.if \\n%=1 .bp
  117. X.SH
  118. \&eXternal Data Representation Standard: Protocol Specification
  119. X.IX XDR RFC
  120. X.IX XDR "protocol specification"
  121. X.LP
  122. X.NH 0
  123. \&Status of this Standard
  124. X.nr OF 1
  125. X.IX XDR "RFC status"
  126. X.LP
  127. Note: This chapter specifies a protocol that Sun Microsystems, Inc., and 
  128. others are using.  It has been designated RFC1014 by the ARPA Network
  129. Information Center.
  130. X.NH 1
  131. \&Introduction
  132. X.LP
  133. XDR is a standard for the description and encoding of data.  It is
  134. useful for transferring data between different computer
  135. architectures, and has been used to communicate data between such
  136. diverse machines as the Sun Workstation, VAX, IBM-PC, and Cray.
  137. XDR fits into the ISO presentation layer, and is roughly analogous in
  138. purpose to X.409, ISO Abstract Syntax Notation.  The major difference
  139. between these two is that XDR uses implicit typing, while X.409 uses
  140. explicit typing.
  141. X.LP
  142. XDR uses a language to describe data formats.  The language can only
  143. be used only to describe data; it is not a programming language.
  144. This language allows one to describe intricate data formats in a
  145. concise manner. The alternative of using graphical representations
  146. (itself an informal language) quickly becomes incomprehensible when
  147. faced with complexity.  The XDR language itself is similar to the C
  148. language [1], just as Courier [4] is similar to Mesa. Protocols such
  149. as Sun RPC (Remote Procedure Call) and the NFS (Network File System)
  150. use XDR to describe the format of their data.
  151. X.LP
  152. The XDR standard makes the following assumption: that bytes (or
  153. octets) are portable, where a byte is defined to be 8 bits of data.
  154. A given hardware device should encode the bytes onto the various
  155. media in such a way that other hardware devices may decode the bytes
  156. without loss of meaning.  For example, the Ethernet standard
  157. suggests that bytes be encoded in "little-endian" style [2], or least
  158. significant bit first.
  159. X.NH 2
  160. \&Basic Block Size
  161. X.IX XDR "basic block size"
  162. X.IX XDR "block size"
  163. X.LP
  164. The representation of all items requires a multiple of four bytes (or
  165. 32 bits) of data.  The bytes are numbered 0 through n-1.  The bytes
  166. are read or written to some byte stream such that byte m always
  167. precedes byte m+1.  If the n bytes needed to contain the data are not
  168. a multiple of four, then the n bytes are followed by enough (0 to 3)
  169. residual zero bytes, r, to make the total byte count a multiple of 4.
  170. X.LP
  171. We include the familiar graphic box notation for illustration and
  172. comparison.  In most illustrations, each box (delimited by a plus
  173. sign at the 4 corners and vertical bars and dashes) depicts a byte.
  174. Ellipses (...) between boxes show zero or more additional bytes where
  175. required.
  176. X.ie t .DS
  177. X.el .DS L
  178. \fIA Block\fP
  179.  
  180. \f(CW+--------+--------+...+--------+--------+...+--------+
  181. | byte 0 | byte 1 |...|byte n-1|    0   |...|    0   |
  182. +--------+--------+...+--------+--------+...+--------+
  183. |<-----------n bytes---------->|<------r bytes------>|
  184. |<-----------n+r (where (n+r) mod 4 = 0)>----------->|\fP
  185.  
  186. X.DE
  187. X.NH 1
  188. \&XDR Data Types
  189. X.IX XDR "data types"
  190. X.IX "XDR data types"
  191. X.LP
  192. Each of the sections that follow describes a data type defined in the
  193. XDR standard, shows how it is declared in the language, and includes
  194. a graphic illustration of its encoding.
  195. X.LP
  196. For each data type in the language we show a general paradigm
  197. declaration.  Note that angle brackets (< and >) denote
  198. variable length sequences of data and square brackets ([ and ]) denote
  199. fixed-length sequences of data.  "n", "m" and "r" denote integers.
  200. For the full language specification and more formal definitions of
  201. terms such as "identifier" and "declaration", refer to
  202. X.I "The XDR Language Specification" ,
  203. below.
  204. X.LP
  205. For some data types, more specific examples are included.  A more
  206. extensive example of a data description is in 
  207. X.I "An Example of an XDR Data Description" ,
  208. below.
  209. X.NH 2
  210. \&Integer
  211. X.IX XDR integer
  212. X.LP
  213. An XDR signed integer is a 32-bit datum that encodes an integer in
  214. the range [-2147483648,2147483647].  The integer is represented in
  215. two's complement notation.  The most and least significant bytes are
  216. 0 and 3, respectively.  Integers are declared as follows:
  217. X.ie t .DS
  218. X.el .DS L
  219. \fIInteger\fP
  220.  
  221. \f(CW(MSB)                   (LSB)
  222. +-------+-------+-------+-------+
  223. |byte 0 |byte 1 |byte 2 |byte 3 |
  224. +-------+-------+-------+-------+
  225. <------------32 bits------------>\fP
  226. X.DE
  227. X.NH 2
  228. \&Unsigned Integer
  229. X.IX XDR "unsigned integer"
  230. X.IX XDR "integer, unsigned"
  231. X.LP
  232. An XDR unsigned integer is a 32-bit datum that encodes a nonnegative
  233. integer in the range [0,4294967295].  It is represented by an
  234. unsigned binary number whose most and least significant bytes are 0
  235. and 3, respectively.  An unsigned integer is declared as follows:
  236. X.ie t .DS
  237. X.el .DS L
  238. \fIUnsigned Integer\fP
  239.  
  240. \f(CW(MSB)                   (LSB)
  241. +-------+-------+-------+-------+
  242. |byte 0 |byte 1 |byte 2 |byte 3 |
  243. +-------+-------+-------+-------+
  244. <------------32 bits------------>\fP
  245. X.DE
  246. X.NH 2
  247. \&Enumeration
  248. X.IX XDR enumeration
  249. X.LP
  250. Enumerations have the same representation as signed integers.
  251. Enumerations are handy for describing subsets of the integers.
  252. Enumerated data is declared as follows:
  253. X.ft CW
  254. X.DS
  255. enum { name-identifier = constant, ... } identifier;
  256. X.DE
  257. For example, the three colors red, yellow, and blue could be
  258. described by an enumerated type:
  259. X.DS
  260. X.ft CW
  261. enum { RED = 2, YELLOW = 3, BLUE = 5 } colors;
  262. X.DE
  263. It is an error to encode as an enum any other integer than those that
  264. have been given assignments in the enum declaration.
  265. X.NH 2
  266. \&Boolean
  267. X.IX XDR boolean
  268. X.LP
  269. Booleans are important enough and occur frequently enough to warrant
  270. their own explicit type in the standard.  Booleans are declared as
  271. follows:
  272. X.DS
  273. X.ft CW
  274. bool identifier;
  275. X.DE
  276. This is equivalent to:
  277. X.DS
  278. X.ft CW
  279. enum { FALSE = 0, TRUE = 1 } identifier;
  280. X.DE
  281. X.NH 2
  282. \&Hyper Integer and Unsigned Hyper Integer
  283. X.IX XDR "hyper integer"
  284. X.IX XDR "integer, hyper"
  285. X.LP
  286. The standard also defines 64-bit (8-byte) numbers called hyper
  287. integer and unsigned hyper integer.  Their representations are the
  288. obvious extensions of integer and unsigned integer defined above.
  289. They are represented in two's complement notation.  The most and
  290. least significant bytes are 0 and 7, respectively.  Their
  291. declarations:
  292. X.ie t .DS
  293. X.el .DS L
  294. \fIHyper Integer\fP
  295. \fIUnsigned Hyper Integer\fP
  296.  
  297. \f(CW(MSB)                                                   (LSB)
  298. +-------+-------+-------+-------+-------+-------+-------+-------+
  299. |byte 0 |byte 1 |byte 2 |byte 3 |byte 4 |byte 5 |byte 6 |byte 7 |
  300. +-------+-------+-------+-------+-------+-------+-------+-------+
  301. <----------------------------64 bits---------------------------->\fP
  302. X.DE
  303. X.NH 2
  304. \&Floating-point
  305. X.IX XDR "integer, floating point"
  306. X.IX XDR "floating-point integer"
  307. X.LP
  308. The standard defines the floating-point data type "float" (32 bits or
  309. 4 bytes).  The encoding used is the IEEE standard for normalized
  310. single-precision floating-point numbers [3].  The following three
  311. fields describe the single-precision floating-point number:
  312. X.RS
  313. X.IP \fBS\fP:
  314. The sign of the number.  Values 0 and  1 represent  positive and
  315. negative, respectively.  One bit.
  316. X.IP \fBE\fP:
  317. The exponent of the number, base 2.  8  bits are devoted to this
  318. field.  The exponent is biased by 127.
  319. X.IP \fBF\fP:
  320. The fractional part of the number's mantissa,  base 2.   23 bits
  321. are devoted to this field.
  322. X.RE
  323. X.LP
  324. Therefore, the floating-point number is described by:
  325. X.DS
  326. (-1)**S * 2**(E-Bias) * 1.F
  327. X.DE
  328. It is declared as follows:
  329. X.ie t .DS
  330. X.el .DS L
  331. \fISingle-Precision Floating-Point\fP
  332.  
  333. \f(CW+-------+-------+-------+-------+
  334. |byte 0 |byte 1 |byte 2 |byte 3 |
  335. S|   E   |           F          |
  336. +-------+-------+-------+-------+
  337. 1|<- 8 ->|<-------23 bits------>|
  338. <------------32 bits------------>\fP
  339. X.DE
  340. Just as the most and least significant bytes of a number are 0 and 3,
  341. the most and least significant bits of a single-precision floating-
  342. point number are 0 and 31.  The beginning bit (and most significant
  343. bit) offsets of S, E, and F are 0, 1, and 9, respectively.  Note that
  344. these numbers refer to the mathematical positions of the bits, and
  345. NOT to their actual physical locations (which vary from medium to
  346. medium).
  347. X.LP
  348. The IEEE specifications should be consulted concerning the encoding
  349. for signed zero, signed infinity (overflow), and denormalized numbers
  350. (underflow) [3].  According to IEEE specifications, the "NaN" (not a
  351. number) is system dependent and should not be used externally.
  352. X.NH 2
  353. \&Double-precision Floating-point
  354. X.IX XDR "integer, double-precision floating point"
  355. X.IX XDR "double-precision floating-point integer"
  356. X.LP
  357. The standard defines the encoding for the double-precision floating-
  358. point data type "double" (64 bits or 8 bytes).  The encoding used is
  359. the IEEE standard for normalized double-precision floating-point
  360. numbers [3].  The standard encodes the following three fields, which
  361. describe the double-precision floating-point number:
  362. X.RS
  363. X.IP \fBS\fP:
  364. The sign of the number.  Values  0 and 1  represent positive and
  365. negative, respectively.  One bit.
  366. X.IP \fBE\fP:
  367. The exponent of the number, base 2.  11 bits are devoted to this
  368. field.  The exponent is biased by 1023.
  369. X.IP \fBF\fP:
  370. The fractional part of the number's  mantissa, base 2.   52 bits
  371. are devoted to this field.
  372. X.RE
  373. X.LP
  374. Therefore, the floating-point number is described by:
  375. X.DS
  376. (-1)**S * 2**(E-Bias) * 1.F
  377. X.DE
  378. It is declared as follows:
  379. X.ie t .DS
  380. X.el .DS L
  381. \fIDouble-Precision Floating-Point\fP
  382.  
  383. \f(CW+------+------+------+------+------+------+------+------+
  384. |byte 0|byte 1|byte 2|byte 3|byte 4|byte 5|byte 6|byte 7|
  385. S|    E   |                    F                        |
  386. +------+------+------+------+------+------+------+------+
  387. 1|<--11-->|<-----------------52 bits------------------->|
  388. <-----------------------64 bits------------------------->\fP
  389. X.DE
  390. Just as the most and least significant bytes of a number are 0 and 3,
  391. the most and least significant bits of a double-precision floating-
  392. point number are 0 and 63.  The beginning bit (and most significant
  393. bit) offsets of S, E , and F are 0, 1, and 12, respectively.  Note
  394. that these numbers refer to the mathematical positions of the bits,
  395. and NOT to their actual physical locations (which vary from medium to
  396. medium).
  397. X.LP
  398. The IEEE specifications should be consulted concerning the encoding
  399. for signed zero, signed infinity (overflow), and denormalized numbers
  400. (underflow) [3].  According to IEEE specifications, the "NaN" (not a
  401. number) is system dependent and should not be used externally.
  402. X.NH 2
  403. \&Fixed-length Opaque Data
  404. X.IX XDR "fixed-length opaque data"
  405. X.IX XDR "opaque data, fixed length"
  406. X.LP
  407. At times, fixed-length uninterpreted data needs to be passed among
  408. machines.  This data is called "opaque" and is declared as follows:
  409. X.DS
  410. X.ft CW
  411. opaque identifier[n];
  412. X.DE
  413. where the constant n is the (static) number of bytes necessary to
  414. contain the opaque data.  If n is not a multiple of four, then the n
  415. bytes are followed by enough (0 to 3) residual zero bytes, r, to make
  416. the total byte count of the opaque object a multiple of four.
  417. X.ie t .DS
  418. X.el .DS L
  419. \fIFixed-Length Opaque\fP
  420.  
  421. \f(CW0        1     ...
  422. +--------+--------+...+--------+--------+...+--------+
  423. | byte 0 | byte 1 |...|byte n-1|    0   |...|    0   |
  424. +--------+--------+...+--------+--------+...+--------+
  425. |<-----------n bytes---------->|<------r bytes------>|
  426. |<-----------n+r (where (n+r) mod 4 = 0)------------>|\fP
  427. X.DE
  428. X.NH 2
  429. \&Variable-length Opaque Data
  430. X.IX XDR "variable-length opaque data"
  431. X.IX XDR "opaque data, variable length"
  432. X.LP
  433. The standard also provides for variable-length (counted) opaque data,
  434. defined as a sequence of n (numbered 0 through n-1) arbitrary bytes
  435. to be the number n encoded as an unsigned integer (as described
  436. below), and followed by the n bytes of the sequence.
  437. X.LP
  438. Byte m of the sequence always precedes byte m+1 of the sequence, and
  439. byte 0 of the sequence always follows the sequence's length (count).
  440. enough (0 to 3) residual zero bytes, r, to make the total byte count
  441. a multiple of four.  Variable-length opaque data is declared in the
  442. following way:
  443. X.DS
  444. X.ft CW
  445. opaque identifier<m>;
  446. X.DE
  447. or
  448. X.DS
  449. X.ft CW
  450. opaque identifier<>;
  451. X.DE
  452. The constant m denotes an upper bound of the number of bytes that the
  453. sequence may contain.  If m is not specified, as in the second
  454. declaration, it is assumed to be (2**32) - 1, the maximum length.
  455. The constant m would normally be found in a protocol specification.
  456. For example, a filing protocol may state that the maximum data
  457. transfer size is 8192 bytes, as follows:
  458. X.DS
  459. X.ft CW
  460. opaque filedata<8192>;
  461. X.DE
  462. This can be illustrated as follows:
  463. X.ie t .DS
  464. X.el .DS L
  465. \fIVariable-Length Opaque\fP
  466.  
  467. \f(CW0     1     2     3     4     5   ...
  468. +-----+-----+-----+-----+-----+-----+...+-----+-----+...+-----+
  469. |        length n       |byte0|byte1|...| n-1 |  0  |...|  0  |
  470. +-----+-----+-----+-----+-----+-----+...+-----+-----+...+-----+
  471. |<-------4 bytes------->|<------n bytes------>|<---r bytes--->|
  472. |<----n+r (where (n+r) mod 4 = 0)---->|\fP
  473. X.DE
  474. X.LP
  475. It   is  an error  to  encode  a  length  greater  than the maximum
  476. described in the specification.
  477. X.NH 2
  478. \&String
  479. X.IX XDR string
  480. X.LP
  481. The standard defines a string of n (numbered 0 through n-1) ASCII
  482. bytes to be the number n encoded as an unsigned integer (as described
  483. above), and followed by the n bytes of the string.  Byte m of the
  484. string always precedes byte m+1 of the string, and byte 0 of the
  485. string always follows the string's length.  If n is not a multiple of
  486. four, then the n bytes are followed by enough (0 to 3) residual zero
  487. bytes, r, to make the total byte count a multiple of four.  Counted
  488. byte strings are declared as follows:
  489. X.DS
  490. X.ft CW
  491. string object<m>;
  492. X.DE
  493. or
  494. X.DS
  495. X.ft CW
  496. string object<>;
  497. X.DE
  498. The constant m denotes an upper bound of the number of bytes that a
  499. string may contain.  If m is not specified, as in the second
  500. declaration, it is assumed to be (2**32) - 1, the maximum length.
  501. The constant m would normally be found in a protocol specification.
  502. For example, a filing protocol may state that a file name can be no
  503. longer than 255 bytes, as follows:
  504. X.DS
  505. X.ft CW
  506. string filename<255>;
  507. X.DE
  508. Which can be illustrated as:
  509. X.ie t .DS
  510. X.el .DS L
  511. \fIA String\fP
  512.  
  513. \f(CW0     1     2     3     4     5   ...
  514. +-----+-----+-----+-----+-----+-----+...+-----+-----+...+-----+
  515. |        length n       |byte0|byte1|...| n-1 |  0  |...|  0  |
  516. +-----+-----+-----+-----+-----+-----+...+-----+-----+...+-----+
  517. |<-------4 bytes------->|<------n bytes------>|<---r bytes--->|
  518. |<----n+r (where (n+r) mod 4 = 0)---->|\fP
  519. X.DE
  520. X.LP
  521. It   is an  error  to  encode  a length greater  than   the maximum
  522. described in the specification.
  523. X.NH 2
  524. \&Fixed-length Array
  525. X.IX XDR "fixed-length array"
  526. X.IX XDR "array, fixed length"
  527. X.LP
  528. Declarations for fixed-length arrays of homogeneous elements are in
  529. the following form:
  530. X.DS
  531. X.ft CW
  532. type-name identifier[n];
  533. X.DE
  534. Fixed-length arrays of elements numbered 0 through n-1 are encoded by
  535. individually encoding the elements of the array in their natural
  536. order, 0 through n-1.  Each element's size is a multiple of four
  537. bytes. Though all elements are of the same type, the elements may
  538. have different sizes.  For example, in a fixed-length array of
  539. strings, all elements are of type "string", yet each element will
  540. vary in its length.
  541. X.ie t .DS
  542. X.el .DS L
  543. \fIFixed-Length Array\fP
  544.  
  545. \f(CW+---+---+---+---+---+---+---+---+...+---+---+---+---+
  546. |   element 0   |   element 1   |...|  element n-1  |
  547. +---+---+---+---+---+---+---+---+...+---+---+---+---+
  548. |<--------------------n elements------------------->|\fP
  549. X.DE
  550. X.NH 2
  551. \&Variable-length Array
  552. X.IX XDR "variable-length array"
  553. X.IX XDR "array, variable length"
  554. X.LP
  555. Counted arrays provide the ability to encode variable-length arrays
  556. of homogeneous elements.  The array is encoded as the element count n
  557. (an unsigned integer) followed by the encoding of each of the array's
  558. elements, starting with element 0 and progressing through element n-
  559. 1.  The declaration for variable-length arrays follows this form:
  560. X.DS
  561. X.ft CW
  562. type-name identifier<m>;
  563. X.DE
  564. or
  565. X.DS
  566. X.ft CW
  567. type-name identifier<>;
  568. X.DE
  569. The constant m specifies the maximum acceptable element count of an
  570. array; if  m is not specified, as  in the second declaration, it is
  571. assumed to be (2**32) - 1.
  572. X.ie t .DS
  573. X.el .DS L
  574. \fICounted Array\fP
  575.  
  576. \f(CW0  1  2  3
  577. +--+--+--+--+--+--+--+--+--+--+--+--+...+--+--+--+--+
  578. |     n     | element 0 | element 1 |...|element n-1|
  579. +--+--+--+--+--+--+--+--+--+--+--+--+...+--+--+--+--+
  580. |<-4 bytes->|<--------------n elements------------->|\fP
  581. X.DE
  582. It is  an error to  encode  a  value of n that  is greater than the
  583. maximum described in the specification.
  584. X.NH 2
  585. \&Structure
  586. X.IX XDR structure
  587. X.LP
  588. Structures are declared as follows:
  589. X.DS
  590. X.ft CW
  591. struct {
  592.     component-declaration-A;
  593.     component-declaration-B;
  594.     \&...
  595. } identifier;
  596. X.DE
  597. The components of the structure are encoded in the order of their
  598. declaration in the structure.  Each component's size is a multiple of
  599. four bytes, though the components may be different sizes.
  600. X.ie t .DS
  601. X.el .DS L
  602. \fIStructure\fP
  603.  
  604. \f(CW+-------------+-------------+...
  605. | component A | component B |...
  606. +-------------+-------------+...\fP
  607. X.DE
  608. X.NH 2
  609. \&Discriminated Union
  610. X.IX XDR "discriminated union"
  611. X.IX XDR union discriminated
  612. X.LP
  613. A discriminated union is a type composed of a discriminant followed
  614. by a type selected from a set of prearranged types according to the
  615. value of the discriminant.  The type of discriminant is either "int",
  616. "unsigned int", or an enumerated type, such as "bool".  The component
  617. types are called "arms" of the union, and are preceded by the value
  618. of the discriminant which implies their encoding.  Discriminated
  619. unions are declared as follows:
  620. X.DS
  621. X.ft CW
  622. union switch (discriminant-declaration) {
  623.     case discriminant-value-A:
  624.     arm-declaration-A;
  625.     case discriminant-value-B:
  626.     arm-declaration-B;
  627.     \&...
  628.     default: default-declaration;
  629. } identifier;
  630. X.DE
  631. Each "case" keyword is followed by a legal value of the discriminant.
  632. The default arm is optional.  If it is not specified, then a valid
  633. encoding of the union cannot take on unspecified discriminant values.
  634. The size of the implied arm is always a multiple of four bytes.
  635. X.LP
  636. The discriminated union is encoded as its discriminant followed by
  637. the encoding of the implied arm.
  638. X.ie t .DS
  639. X.el .DS L
  640. \fIDiscriminated Union\fP
  641.  
  642. \f(CW0   1   2   3
  643. +---+---+---+---+---+---+---+---+
  644. |  discriminant |  implied arm  |
  645. +---+---+---+---+---+---+---+---+
  646. |<---4 bytes--->|\fP
  647. X.DE
  648. X.NH 2
  649. \&Void
  650. X.IX XDR void
  651. X.LP
  652. An XDR void is a 0-byte quantity.  Voids are useful for describing
  653. operations that take no data as input or no data as output. They are
  654. also useful in unions, where some arms may contain data and others do
  655. not.  The declaration is simply as follows:
  656. X.DS
  657. X.ft CW
  658. void;
  659. X.DE
  660. Voids are illustrated as follows:
  661. X.ie t .DS
  662. X.el .DS L
  663. \fIVoid\fP
  664.  
  665. \f(CW  ++
  666.   ||
  667.   ++
  668. --><-- 0 bytes\fP
  669. X.DE
  670. X.NH 2
  671. \&Constant
  672. X.IX XDR constant
  673. X.LP
  674. The data declaration for a constant follows this form:
  675. X.DS
  676. X.ft CW
  677. const name-identifier = n;
  678. X.DE
  679. "const" is used to define a symbolic name for a constant; it does not
  680. declare any data.  The symbolic constant may be used anywhere a
  681. regular constant may be used.  For example, the following defines a
  682. symbolic constant DOZEN, equal to 12.
  683. X.DS
  684. X.ft CW
  685. const DOZEN = 12;
  686. X.DE
  687. X.NH 2
  688. \&Typedef
  689. X.IX XDR typedef
  690. X.LP
  691. "typedef" does not declare any data either, but serves to define new
  692. identifiers for declaring data. The syntax is:
  693. X.DS
  694. X.ft CW
  695. typedef declaration;
  696. X.DE
  697. The new type name is actually the variable name in the declaration
  698. part of the typedef.  For example, the following defines a new type
  699. called "eggbox" using an existing type called "egg":
  700. X.DS
  701. X.ft CW
  702. typedef egg eggbox[DOZEN];
  703. X.DE
  704. Variables declared using the new type name have the same type as the
  705. new type name would have in the typedef, if it was considered a
  706. variable.  For example, the following two declarations are equivalent
  707. in declaring the variable "fresheggs":
  708. X.DS
  709. X.ft CW
  710. eggbox  fresheggs;
  711. egg     fresheggs[DOZEN];
  712. X.DE
  713. When a typedef involves a struct, enum, or union definition, there is
  714. another (preferred) syntax that may be used to define the same type.
  715. In general, a typedef of the following form:
  716. X.DS
  717. X.ft CW
  718. typedef <<struct, union, or enum definition>> identifier;
  719. X.DE
  720. may be converted to the alternative form by removing the "typedef"
  721. part and placing the identifier after the "struct", "union", or
  722. "enum" keyword, instead of at the end.  For example, here are the two
  723. ways to define the type "bool":
  724. X.DS
  725. X.ft CW
  726. typedef enum {    /* \fIusing typedef\fP */
  727.     FALSE = 0,
  728.     TRUE = 1
  729.     } bool;
  730.  
  731. enum bool {       /* \fIpreferred alternative\fP */
  732.     FALSE = 0,
  733.     TRUE = 1
  734.     };
  735. X.DE
  736. The reason this syntax is preferred is one does not have to wait
  737. until the end of a declaration to figure out the name of the new
  738. type.
  739. X.NH 2
  740. \&Optional-data
  741. X.IX XDR "optional data"
  742. X.IX XDR "data, optional"
  743. X.LP
  744. Optional-data is one kind of union that occurs so frequently that we
  745. give it a special syntax of its own for declaring it.  It is declared
  746. as follows:
  747. X.DS
  748. X.ft CW
  749. type-name *identifier;
  750. X.DE
  751. This is equivalent to the following union:
  752. X.DS
  753. X.ft CW
  754. union switch (bool opted) {
  755.     case TRUE:
  756.     type-name element;
  757.     case FALSE:
  758.     void;
  759. } identifier;
  760. X.DE
  761. It is also equivalent to the following variable-length array
  762. declaration, since the boolean "opted" can be interpreted as the
  763. length of the array:
  764. X.DS
  765. X.ft CW
  766. type-name identifier<1>;
  767. X.DE
  768. Optional-data is not so interesting in itself, but it is very useful
  769. for describing recursive data-structures such as linked-lists and
  770. trees.  For example, the following defines a type "stringlist" that
  771. encodes lists of arbitrary length strings:
  772. X.DS
  773. X.ft CW
  774. struct *stringlist {
  775.     string item<>;
  776.     stringlist next;
  777. };
  778. X.DE
  779. It could have been equivalently declared as the following union:
  780. X.DS
  781. X.ft CW
  782. union stringlist switch (bool opted) {
  783.     case TRUE:
  784.         struct {
  785.             string item<>;
  786.             stringlist next;
  787.         } element;
  788.     case FALSE:
  789.         void;
  790. };
  791. X.DE
  792. or as a variable-length array:
  793. X.DS
  794. X.ft CW
  795. struct stringlist<1> {
  796.     string item<>;
  797.     stringlist next;
  798. };
  799. X.DE
  800. Both of these declarations obscure the intention of the stringlist
  801. type, so the optional-data declaration is preferred over both of
  802. them.  The optional-data type also has a close correlation to how
  803. recursive data structures are represented in high-level languages
  804. such as Pascal or C by use of pointers. In fact, the syntax is the
  805. same as that of the C language for pointers.
  806. X.NH 2
  807. \&Areas for Future Enhancement
  808. X.IX XDR futures
  809. X.LP
  810. The XDR standard lacks representations for bit fields and bitmaps,
  811. since the standard is based on bytes.  Also missing are packed (or
  812. binary-coded) decimals.
  813. X.LP
  814. The intent of the XDR standard was not to describe every kind of data
  815. that people have ever sent or will ever want to send from machine to
  816. machine. Rather, it only describes the most commonly used data-types
  817. of high-level languages such as Pascal or C so that applications
  818. written in these languages will be able to communicate easily over
  819. some medium.
  820. X.LP
  821. One could imagine extensions to XDR that would let it describe almost
  822. any existing protocol, such as TCP.  The minimum necessary for this
  823. are support for different block sizes and byte-orders.  The XDR
  824. discussed here could then be considered the 4-byte big-endian member
  825. of a larger XDR family.
  826. X.NH 1
  827. \&Discussion
  828. X.sp 2
  829. X.NH 2
  830. \&Why a Language for Describing Data?
  831. X.IX XDR language
  832. X.LP
  833. There are many advantages in using a data-description language such
  834. as  XDR  versus using  diagrams.   Languages are  more  formal than
  835. diagrams   and   lead  to less  ambiguous   descriptions  of  data.
  836. Languages are also easier  to understand and allow  one to think of
  837. other   issues instead of  the   low-level details of bit-encoding.
  838. Also,  there is  a close analogy  between the  types  of XDR and  a
  839. high-level language   such  as C   or    Pascal.   This makes   the
  840. implementation of XDR encoding and decoding modules an easier task.
  841. Finally, the language specification itself  is an ASCII string that
  842. can be passed from  machine to machine  to perform  on-the-fly data
  843. interpretation.
  844. X.NH 2
  845. \&Why Only one Byte-Order for an XDR Unit?
  846. X.IX XDR "byte order"
  847. X.LP
  848. Supporting two byte-orderings requires a higher level protocol for
  849. determining in which byte-order the data is encoded.  Since XDR is
  850. not a protocol, this can't be done.  The advantage of this, though,
  851. is that data in XDR format can be written to a magnetic tape, for
  852. example, and any machine will be able to interpret it, since no
  853. higher level protocol is necessary for determining the byte-order.
  854. X.NH 2
  855. \&Why does XDR use Big-Endian Byte-Order?
  856. X.LP
  857. Yes, it is unfair, but having only one byte-order means you have to
  858. be unfair to somebody.  Many architectures, such as the Motorola
  859. 68000 and IBM 370, support the big-endian byte-order.
  860. X.NH 2
  861. \&Why is the XDR Unit Four Bytes Wide?
  862. X.LP
  863. There is a tradeoff in choosing the XDR unit size.  Choosing a small
  864. size such as two makes the encoded data small, but causes alignment
  865. problems for machines that aren't aligned on these boundaries.  A
  866. large size such as eight means the data will be aligned on virtually
  867. every machine, but causes the encoded data to grow too big.  We chose
  868. four as a compromise.  Four is big enough to support most
  869. architectures efficiently, except for rare machines such as the
  870. eight-byte aligned Cray.  Four is also small enough to keep the
  871. encoded data restricted to a reasonable size.
  872. X.NH 2
  873. \&Why must Variable-Length Data be Padded with Zeros?
  874. X.IX XDR "variable-length data"
  875. X.LP
  876. It is desirable that the same data encode into the same thing on all
  877. machines, so that encoded data can be meaningfully compared or
  878. checksummed.  Forcing the padded bytes to be zero ensures this.
  879. X.NH 2
  880. \&Why is there No Explicit Data-Typing?
  881. X.LP
  882. Data-typing has a relatively high cost for what small advantages it
  883. may have.  One cost is the expansion of data due to the inserted type
  884. fields.  Another is the added cost of interpreting these type fields
  885. and acting accordingly.  And most protocols already know what type
  886. they expect, so data-typing supplies only redundant information.
  887. However, one can still get the benefits of data-typing using XDR. One
  888. way is to encode two things: first a string which is the XDR data
  889. description of the encoded data, and then the encoded data itself.
  890. Another way is to assign a value to all the types in XDR, and then
  891. define a universal type which takes this value as its discriminant
  892. and for each value, describes the corresponding data type.
  893. X.NH 1
  894. \&The XDR Language Specification
  895. X.IX XDR language
  896. X.sp 1
  897. X.NH 2
  898. \&Notational Conventions
  899. X.IX "XDR language" notation
  900. X.LP
  901. This specification  uses an extended Backus-Naur Form  notation for
  902. describing the XDR language.   Here is  a brief description  of the
  903. notation:
  904. X.IP  1.
  905. The characters
  906. X.I | ,
  907. X.I ( ,
  908. X.I ) ,
  909. X.I [ ,
  910. X.I ] ,
  911. X.I " ,
  912. and
  913. X.I * 
  914. are special.
  915. X.IP  2.
  916. Terminal symbols are  strings of any  characters surrounded by
  917. double quotes.
  918. X.IP  3.
  919. Non-terminal symbols are strings of non-special characters.
  920. X.IP  4.
  921. Alternative items are separated by a vertical bar ("\fI|\fP").
  922. X.IP  5.
  923. Optional items are enclosed in brackets.
  924. X.IP  6.
  925. Items are grouped together by enclosing them in parentheses.
  926. X.IP  7.
  927. A
  928. X.I * 
  929. following an item means  0 or more  occurrences of that item.
  930. X.LP
  931. For example,  consider  the  following pattern:
  932. X.DS L
  933. "a " "very" (", " " very")* [" cold " "and"]  " rainy " ("day" | "night")
  934. X.DE
  935. X.LP
  936. An infinite  number of  strings match  this pattern. A few  of them
  937. are:
  938. X.DS
  939. "a very rainy day"
  940. "a very, very rainy day"
  941. "a very cold and  rainy day"
  942. "a very, very, very cold and  rainy night"
  943. X.DE
  944. X.NH 2
  945. \&Lexical Notes
  946. X.IP  1.
  947. Comments begin with '/*' and terminate with '*/'.
  948. X.IP  2.
  949. White space serves to separate items and is otherwise ignored.
  950. X.IP  3.
  951. An identifier is a letter followed by  an optional sequence of
  952. letters, digits or underbar ('_').  The case of identifiers is
  953. not ignored.
  954. X.IP  4.
  955. A  constant is  a  sequence  of  one  or  more decimal digits,
  956. optionally preceded by a minus-sign ('-').
  957. X.NH 2
  958. \&Syntax Information
  959. X.IX "XDR language" syntax
  960. X.DS
  961. X.ft CW
  962. declaration:
  963.     type-specifier identifier
  964.     | type-specifier identifier "[" value "]"
  965.     | type-specifier identifier "<" [ value ] ">"
  966.     | "opaque" identifier "[" value "]"
  967.     | "opaque" identifier "<" [ value ] ">"
  968.     | "string" identifier "<" [ value ] ">"
  969.     | type-specifier "*" identifier
  970.     | "void"
  971. X.DE
  972. X.DS
  973. X.ft CW
  974. value:
  975.     constant
  976.     | identifier
  977.  
  978. type-specifier:
  979.       [ "unsigned" ] "int"
  980.     | [ "unsigned" ] "hyper"
  981.     | "float"
  982.     | "double"
  983.     | "bool"
  984.     | enum-type-spec
  985.     | struct-type-spec
  986.     | union-type-spec
  987.     | identifier
  988. X.DE
  989. X.DS
  990. X.ft CW
  991. enum-type-spec:
  992.     "enum" enum-body
  993.  
  994. enum-body:
  995.     "{"
  996.     ( identifier "=" value )
  997.     ( "," identifier "=" value )*
  998.     "}"
  999. X.DE
  1000. X.DS
  1001. X.ft CW
  1002. struct-type-spec:
  1003.     "struct" struct-body
  1004.  
  1005. struct-body:
  1006.     "{"
  1007.     ( declaration ";" )
  1008.     ( declaration ";" )*
  1009.     "}"
  1010. X.DE
  1011. X.DS
  1012. X.ft CW
  1013. union-type-spec:
  1014.     "union" union-body
  1015.  
  1016. union-body:
  1017.     "switch" "(" declaration ")" "{"
  1018.     ( "case" value ":" declaration ";" )
  1019.     ( "case" value ":" declaration ";" )*
  1020.     [ "default" ":" declaration ";" ]
  1021.     "}"
  1022.  
  1023. constant-def:
  1024.     "const" identifier "=" constant ";"
  1025. X.DE
  1026. X.DS
  1027. X.ft CW
  1028. type-def:
  1029.     "typedef" declaration ";"
  1030.     | "enum" identifier enum-body ";"
  1031.     | "struct" identifier struct-body ";"
  1032.     | "union" identifier union-body ";"
  1033.  
  1034. definition:
  1035.     type-def
  1036.     | constant-def
  1037.  
  1038. specification:
  1039.     definition *
  1040. X.DE
  1041. X.NH 3
  1042. \&Syntax Notes
  1043. X.IX "XDR language" syntax
  1044. X.LP
  1045. X.IP  1.
  1046. The following are keywords and cannot be used as identifiers:
  1047. "bool", "case", "const", "default", "double", "enum", "float",
  1048. "hyper", "opaque", "string", "struct", "switch", "typedef", "union",
  1049. "unsigned" and "void".
  1050. X.IP  2.
  1051. Only unsigned constants may be used as size specifications for
  1052. arrays.  If an identifier is used, it must have been declared
  1053. previously as an unsigned constant in a "const" definition.
  1054. X.IP  3.
  1055. Constant and type identifiers within the scope of a specification
  1056. are in the same name space and must be declared uniquely within this
  1057. scope.
  1058. X.IP  4.
  1059. Similarly, variable names must  be unique within  the scope  of
  1060. struct and union declarations. Nested struct and union declarations
  1061. create new scopes.
  1062. X.IP  5.
  1063. The discriminant of a union must be of a type that evaluates to
  1064. an integer. That is, "int", "unsigned int", "bool", an enumerated
  1065. type or any typedefed type that evaluates to one of these is legal.
  1066. Also, the case values must be one of the legal values of the
  1067. discriminant.  Finally, a case value may not be specified more than
  1068. once within the scope of a union declaration.
  1069. X.NH 1
  1070. \&An Example of an XDR Data Description
  1071. X.LP
  1072. Here is a short XDR data description of a thing called a "file",
  1073. which might be used to transfer files from one machine to another.
  1074. X.ie t .DS
  1075. X.el .DS L
  1076. X.ft CW
  1077.  
  1078. const MAXUSERNAME = 32;     /*\fI max length of a user name \fP*/
  1079. const MAXFILELEN = 65535;   /*\fI max length of a file      \fP*/
  1080. const MAXNAMELEN = 255;     /*\fI max length of a file name \fP*/
  1081.  
  1082. X.ft I
  1083. /*
  1084.  * Types of files:
  1085.  */
  1086. X.ft CW
  1087.  
  1088. enum filekind {
  1089.     TEXT = 0,       /*\fI ascii data \fP*/
  1090.     DATA = 1,       /*\fI raw data   \fP*/
  1091.     EXEC = 2        /*\fI executable \fP*/
  1092. };
  1093.  
  1094. X.ft I
  1095. /*
  1096.  * File information, per kind of file:
  1097.  */
  1098. X.ft CW
  1099.  
  1100. union filetype switch (filekind kind) {
  1101.     case TEXT:
  1102.         void;                           /*\fI no extra information \fP*/
  1103.     case DATA:
  1104.         string creator<MAXNAMELEN>;     /*\fI data creator         \fP*/
  1105.     case EXEC:
  1106.         string interpretor<MAXNAMELEN>; /*\fI program interpretor  \fP*/
  1107. };
  1108.  
  1109. X.ft I
  1110. /*
  1111.  * A complete file:
  1112.  */
  1113. X.ft CW
  1114.  
  1115. struct file {
  1116.     string filename<MAXNAMELEN>; /*\fI name of file \fP*/
  1117.     filetype type;               /*\fI info about file \fP*/
  1118.     string owner<MAXUSERNAME>;   /*\fI owner of file   \fP*/
  1119.     opaque data<MAXFILELEN>;     /*\fI file data       \fP*/
  1120. };
  1121. X.DE
  1122. X.LP
  1123. Suppose now that there is  a user named  "john" who wants to  store
  1124. his lisp program "sillyprog" that contains just  the data "(quit)".
  1125. His file would be encoded as follows:
  1126. X.TS
  1127. box tab (&) ;
  1128. lfI lfI lfI lfI
  1129. rfL rfL rfL l .
  1130. Offset&Hex Bytes&ASCII&Description
  1131. _
  1132. 0&00 00 00 09&....&Length of filename = 9
  1133. 4&73 69 6c 6c&sill&Filename characters
  1134. 8&79 70 72 6f&ypro& ... and more characters ...
  1135. 12&67 00 00 00&g...& ... and 3 zero-bytes of fill
  1136. 16&00 00 00 02&....&Filekind is EXEC = 2
  1137. 20&00 00 00 04&....&Length of interpretor = 4
  1138. 24&6c 69 73 70&lisp&Interpretor characters
  1139. 28&00 00 00 04&....&Length of owner = 4
  1140. 32&6a 6f 68 6e&john&Owner characters
  1141. 36&00 00 00 06&....&Length of file data = 6
  1142. 40&28 71 75 69&(qui&File data bytes ...
  1143. 44&74 29 00 00&t)..& ... and 2 zero-bytes of fill
  1144. X.TE
  1145. X.NH 1
  1146. \&References
  1147. X.LP
  1148. [1]  Brian W. Kernighan & Dennis M. Ritchie, "The C Programming
  1149. Language", Bell Laboratories, Murray Hill, New Jersey, 1978.
  1150. X.LP
  1151. [2]  Danny Cohen, "On Holy Wars and a Plea for Peace", IEEE Computer,
  1152. October 1981.
  1153. X.LP
  1154. [3]  "IEEE Standard for Binary Floating-Point Arithmetic", ANSI/IEEE
  1155. Standard 754-1985, Institute of Electrical and Electronics
  1156. Engineers, August 1985.
  1157. X.LP
  1158. [4]  "Courier: The Remote Procedure Call Protocol", XEROX
  1159. Corporation, XSIS 038112, December 1981.
  1160. Funky_Stuff
  1161. cd ..
  1162. echo more files to follow
  1163. exit
  1164.